const Koa = require('koa')
const router = require('./router')
const ejs = require('koa-ejs')// 页面模板内容
const path = require('path')// 处理路径问题
const static = require('koa-static')// 处理静态文件
const body = require('koa-body')// 解析请求内容
const app = new Koa()

app.use(require('./libs/error')) // 错误处理
app.use(require('./libs/interceptor')) // 拦截浏览器请求

app.use(body())

ejs(app, {
  root: path.resolve(__dirname, 'template'),
  layout: false,
  viewExt: 'ejs',
  cache: false,
  debug: false
})

// 引入路由
app.use(router.routes())
// 引入静态文件
app.use(static(path.resolve(__dirname, './static')))

app.listen(3000, () => {
  console.log('The server is start at port ' + 3000)
  console.log('http://localhost:3000/home')
})